﻿using Castle.DynamicProxy;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using OOP.Command.DesignPattern.Mode1;
using OOP.Command.DesignPattern.Mode2;
using OOP.DesignPattern.App.Demo;
using OOP.Prototype.DesignPattern.BaseData;
using OOP.Proxy.DesignPattern.IServices;
using OOP.Proxy.DesignPattern.Proxy;
using OOP.Proxy.DesignPattern.Services;
using OOP.SimpleFactory.DesignPattern;
using OOP.Strage.DesignPattern;
using OOP.Template.DesignPattern;



#region 工厂+策略+模板模式联调
{
    string userChoice = "Alipay";  // 用户选择的支付方式
    PaymentStrategyFactory factory = new PaymentStrategyFactory();

    IPaymentStrategy paymentStrategy = factory.Create(userChoice);
    PaymentProcessor paymentProcessor = new AlipayProcessor(paymentStrategy);
    //paymentProcessor.ExecutePayment(100m);
}
#endregion

#region 命令模式(传统方式)
{
    Light light = new Light();
    Fan fan = new Fan();

    OOP.Command.DesignPattern.Mode1.RemoteControl remoteControl = new OOP.Command.DesignPattern.Mode1.RemoteControl(light,fan);
    //remoteControl.PressLightButton();
    //remoteControl.PressFanButton();
}
#endregion

#region 命令模式
{
    Light light = new Light();
    Fan fan = new Fan();

    LightOnCommand command1 = new LightOnCommand(light);
    FanStartCommand command2 = new FanStartCommand(fan);

    //OOP.Command.DesignPattern.Mode2.RemoteControl remoteControl = new OOP.Command.DesignPattern.Mode2.RemoteControl();
    //remoteControl.SetCommand(command1);
    //remoteControl.PressButton();
    //remoteControl.PressUndo();

    //remoteControl.SetCommand(command2);
    //remoteControl.PressButton();
    //remoteControl.PressUndo();
}
#endregion

#region 原型模式
{
    Department department = new Department
    {
        DeptID = "DPID0000001",
        DepartmentName = "软件一部",
        Description = "负责软件研发工作",
        StaffNum = 61,
        Staffs = new List<User>()
    };
    department.Staffs.Add(new User() { ID = "UID000001",Name = "User1", Password = "12345678",Gender = 0,Age = 18,Address = "路北区大庆道",City = "西红市",Region = "台北", Country = "中国", Email = "123456@qq.com", PostalCode = "046350", Phone = "15498729874" });

    JsonConvert.DefaultSettings = () =>
    {
        return new JsonSerializerSettings()
        {
            ContractResolver = new CamelCasePropertyNamesContractResolver(),
            DateTimeZoneHandling = DateTimeZoneHandling.Utc,
            DateFormatString = "yyyy-MM-dd HH:mm:ss"
        };
    };

    Department department2 = (Department)department.Clone();
    department2.DeptID = "DPID0000001";
    department2.DepartmentName = "软件二部";
    department2.StaffNum = 60;
    department2.Staffs[0].ID = "UID000004";
    department2.Staffs[0].Name = "User4";
    department2.Staffs[0].Password = "123456";

    //string json1 = JsonConvert.SerializeObject(department, Formatting.Indented);
    //string json2 = JsonConvert.SerializeObject(department2, Formatting.Indented);

    //Console.WriteLine(json1);
    //Console.WriteLine(json2);
}
#endregion

#region 代理模式（动态代理）
{
    ProxyGenerator proxyGenerator = new ProxyGenerator();
    IOrderService orderService = new OrderService();
    IOrderService orderServiceProxy = proxyGenerator.CreateInterfaceProxyWithTarget<IOrderService>(orderService,new OrderServiceInterceptor());
    orderServiceProxy.Order();
    orderServiceProxy.Payment();
}
#endregion

#region 构造函数推断
{
    Type type = typeof(Worker);
    System.Reflection.ConstructorInfo[] constructorInfos = type.GetConstructors();
}
#endregion